package com.zb.hello.controller;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

public class W2test {
	
	@Test
	public void watest() {
		String str = "select ${name} ${age} ${}";
		//判断是否有占位符
		/*
		 * 方法1
		 */
		
		Pattern pattern = Pattern.compile("([$]\\{\\w+\\})"); 
		Matcher m = pattern.matcher(str); 
		if(m.find()) {
			System.out.println(m.group());
		}
		
		/*
		 * 方法二
		 */
	   /* Pattern pattern = Pattern.compile("(\\$\\{[^\\}]*\\})"); 
		Matcher m = pattern.matcher(str); 
		while(m.find()){
		System.out.println(m.group());
		}*/
		
		/**
		 * 方法三
		 */
    	/*Pattern p = Pattern.compile("\\$\\{(.*?)\\}");//正则表达式，取=和|之间的字符串，不包括=和|
    	Matcher m = p.matcher(str);
    	 while(m.find()) {
    		 	System.out.println(m.group(0));//m.group(1)不包括这两个字符
 
        }*/
	}

	
	public void listTest() {
		List<Map<String, String>> lists = new ArrayList<>();
		Map<String, String> m = new HashMap<>();
		m.put("name", "张三");
		m.put("time", "2018-10-28");
		lists.add(m);
		Map<String, String> m2 = new HashMap<>();
		m2.put("name", "李四");
		m2.put("time", "2017-10-28");
		lists.add(m);
		Map<String, String> m3 = new HashMap<>();
		m3.put("name", "王五");
		m3.put("time", "2018-10-28");
		lists.add(m);
		Map<String, String> m4 = new HashMap<>();
		m4.put("name", "赵六");
		m4.put("time", "2018-11-28");
		lists.add(m);
		
		
	}
	
	public void strToDate() {
		/*DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		LocalDate date = LocalDate.parse("2018-10-28", dateTimeFormatter);
		System.out.println(date);*/
		//long l = date.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
				LocalDateTime date1 = LocalDateTime.now();

		
		LocalDateTime date = LocalDateTime.parse("2018-10-28 12:23:15",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		
		long l = date.atZone(ZoneId.of("+8")).toInstant().toEpochMilli();
		//1540700595000
		System.out.println(l);
		System.out.println(date1);
		System.out.println(new Date());
	}
}
